import request from '@/utils/request'
import { makeFormData, transferFormData } from '@/utils/util'

const api = {
  detail: 'web/staff/base_info',
  detailList: 'api/staff_extend/info/list',
  submit: 'api/staff_extend/info',
  scoreList: 'api/staff_rank/log/list',
  score: 'api/staff_rank/log',
  rankList: '/api/staff_rank/rank/list',
  rank: 'api/staff_rank/rank',
  quit: '/web/staff/quit',
  entry: '/web/staff/entry',
  staffRoles: 'web/staff/staff_roles',
  setStaffRoles: 'web/staff/staff_roles',
  monthRecords: '/v2/report/staff_checkin/monthRecords',
  dailyRecords: '/v2/report/staff_checkin/dailyRecords'
}

export function getDetailById (data = {}) {
  return request({
    url: api.detail,
    method: 'post',
    data: makeFormData(data)
  })
}

export function getListByStaffId (params = {}) {
  return request({
    url: api.detailList,
    method: 'get',
    params
  })
}

export function submitStaff (params = {}, data = {}, method = 'post') {
  const formdata = new FormData()
  transferFormData(data, formdata)
  return request({
    url: api.submit,
    method,
    params,
    data: formdata
  })
}

export function getScoreList (params = {}) {
  return request({
    url: api.scoreList,
    method: 'get',
    params
  })
}

export function submitScore (params = {}, data = {}, method = 'post') {
  return request({
    url: api.score,
    method,
    params,
    data: makeFormData(data)
  })
}

export function staffQuit (params = {}, data = {}, method = 'post') {
  return request({
    url: api.quit,
    method,
    params,
    data
  })
}

export function staffEntry (params = {}, data = {}, method = 'post') {
  return request({
    url: api.entry,
    method,
    params,
    data
  })
}

export function setStaffRoles (params = {}) {
  return request({
    url: api.setStaffRoles,
    method: 'post',
    params
  })
}

export function getStaffRoles (params = {}) {
  return request({
    url: api.staffRoles,
    method: 'get',
    params
  })
}

export function getStaffMonthRecords (params = {}) {
  return request({
    url: api.monthRecords,
    method: 'get',
    params
  })
}

export function getStaffDailyRecords (params = {}) {
  return request({
    url: api.dailyRecords,
    method: 'get',
    params
  })
}
